package com.wangzeqi.changliaoba.contacts;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMContactManager;
import com.easemob.exceptions.EaseMobException;
import com.wangzeqi.changliaba.dao.ContactsEntity;
import com.wangzeqi.changliaba.dao.ContactsEntityDao;
import com.wangzeqi.changliaoba.R;
import com.wangzeqi.changliaoba.base.ActivityCollector;
import com.wangzeqi.changliaoba.base.BaseActivity;
import com.wangzeqi.changliaoba.messege.ChatActivity;
import com.wangzeqi.changliaoba.messege.MyClick;

/**
 * Created by dllo on 16/3/3.
 */
public class ContactActivity extends BaseActivity implements View.OnClickListener {
    private TextView friend_remarks, friend_id_detail, friend_nickname_detail, friend_tellphone;
    private Button send_message_to_friend, send_vedio_to_friend;
    private ImageView friend_photo1, friend_photo2, friend_photo3,friend_detail_back;
    private TextView textViewIDDetails;
    private Button sendMessageFriendBtn;
    private Toolbar toolbar;
    private static MyClick myClick;

    public static void setMyClick(MyClick myClick) {
        ContactActivity.myClick = myClick;
    }

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_details);
        ActivityCollector.addActivity(this);
        friend_remarks = (TextView) findViewById(R.id.friend_remarks);
        friend_id_detail = (TextView) findViewById(R.id.friend_id_detail);
        friend_nickname_detail = (TextView) findViewById(R.id.friend_nickname_detail);
        friend_tellphone = (TextView) findViewById(R.id.friend_tellphone);
        send_message_to_friend = (Button) findViewById(R.id.send_message_to_friend);
        send_vedio_to_friend = (Button) findViewById(R.id.send_vedio_to_friend);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        friend_detail_back = (ImageView)findViewById(R.id.friend_detail_back);
        toolbar.setTitle(" ");
        toolbar.setTitleTextColor(Color.parseColor("#ffffff"));
        send_message_to_friend.setOnClickListener(this);
        send_vedio_to_friend.setOnClickListener(this);
        friend_detail_back.setOnClickListener(this);

        Intent intent = getIntent();
        String username = intent.getStringExtra("username");
        textViewIDDetails = (TextView) findViewById(R.id.friend_id_detail);
        sendMessageFriendBtn = (Button) findViewById(R.id.send_message_to_friend);
        textViewIDDetails.setText(username);
        sendMessageFriendBtn.setOnClickListener(this);
        setSupportActionBar(toolbar);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.send_message_to_friend:
                Intent intent = new Intent(ContactActivity.this, ChatActivity.class);
                intent.putExtra("username", textViewIDDetails.getText().toString());
                startActivity(intent);
                finish();
                break;
            case R.id.send_vedio_to_friend:
                break;
            case R.id.friend_detail_back:
                finish();
                break;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.friend_detail_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.friend_remarks:
                Toast.makeText(this, "好友备注", Toast.LENGTH_SHORT).show();
                break;
            case R.id.send_friend_msg:
                Toast.makeText(this, "发送名片", Toast.LENGTH_SHORT).show();
                break;
            case R.id.friend_delete:
                try {
                    EMContactManager.getInstance().deleteContact(textViewIDDetails.getText().toString());
                } catch (EaseMobException e) {
                    e.printStackTrace();
                }
                myClick.deleteFriend(textViewIDDetails.getText().toString());
                finish();

                break;
            case R.id.friend_permission:
                Toast.makeText(this, "朋友圈权限", Toast.LENGTH_SHORT).show();
                break;
            case R.id.add_friend_to_desktop:
                Toast.makeText(this, "发送至桌面", Toast.LENGTH_SHORT).show();
                break;

        }
        return true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }
}
